import random
import time
from queue import Queue
import threading


def producer(q):
    l=['panzer IV','Puma','Stug 3']
    factory=['belin','luer','haber']

    print( '准备生产坦克 ')
    p=random.choice(l)
    f=random.choice(factory)
    q.put(p)
    time.sleep(3)
    print(threading.current_thread().name, '生产%s一辆'%p)


def consumer(q):
    while True:
        size=q.qsize()
        print('我们还有%s辆坦克'%size)
        print(threading.current_thread().name, '坦克投入战斗')
        m=q.get()
        time.sleep(2)
        print(threading.current_thread().name, '%s损失一辆'%m)


if __name__ == '__main__':
    q = Queue(maxsize=5)
    for i in range(15):
        p1=threading.Thread(target=producer, args=(q,))
        p1.start()

        # p2=threading.Thread(target=producer, args=(q,))
        # p2.start()

    c=threading.Thread(target=consumer, args=(q,))
    c.start()
    c.setDaemon(True)
    time.sleep(20)
    print('end')